﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace _395_2d
{
    class Boss : Ship
    {
        Vector2 Velocity = new Vector2(60, 30);

        public Boss(SpriteManager sm, double SpawnTime)
        {
            Texture = "NPC_Boss";
            Health = 1000;

            LastShot = new List<double>();
            MountedWeapons = new List<MountedWeapon>();

        //public Vector2 Location;
        //public double WarmUpTime;
            MountedWeapon[] m = new MountedWeapon[10];
            for( int i = 0; i < 10; i++ ) {
                m[i] = new MountedWeapon();
                m[i].Weapon = "NPC Blue Ball";
                m[i].Aim = new Vector2(0, 150);
                LastShot.Add(SpawnTime + 5);
            }

            m[0].Location = new Vector2(47, 125);
            m[1].Location = new Vector2(79, 145);
            m[2].Location = new Vector2(130, 185);
            m[3].Location = new Vector2(192, 185);
            m[4].Location = new Vector2(246, 145);
            m[5].Location = new Vector2(277, 125);
            m[6].Location = new Vector2(130, 185);
            m[7].Location = new Vector2(130, 185);
            m[8].Location = new Vector2(192, 185);
            m[9].Location = new Vector2(192, 185);

            m[6].Aim = new Vector2(-150, 150);
            m[7].Aim = new Vector2(150, 150);
            m[8].Aim = new Vector2(-150, 150);
            m[9].Aim = new Vector2(150, 150);

            MountedWeapons.AddRange(m);

            MountedWeapons.Add(m[0]);
            LastShot.Add(SpawnTime + 5.2);
            MountedWeapons.Add(m[0]);
            LastShot.Add(SpawnTime + 5.4);

            MountedWeapons.Add(m[5]);
            LastShot.Add(SpawnTime + 5.2);
            MountedWeapons.Add(m[5]);
            LastShot.Add(SpawnTime + 5.4);

            Texture2D tex = (Texture2D)Content.Textures[Texture];
            bounds = new BoundingBox(new Vector2(-tex.Width + 1, -tex.Height + 1), new Vector2(tex.Width, tex.Height));
            SM = sm;
        }

        public override void Update(GameTime gt)
        {
            if ( bounds.topLeft.Y < 0 )
               Velocity.Y = 30;
            if ( bounds.topLeft.Y > 75 )
                Velocity.Y = -30;

            if ( bounds.topLeft.X < 0 )
                Velocity.X = 60;
            if ( bounds.topLeft.X + bounds.size.X > 800 )
                Velocity.X = -60;

            bounds.topLeft += Velocity * (float)gt.ElapsedGameTime.TotalSeconds;
        }

        public override void shoot(GameTime gt)
        {
            for ( int i = 0; i < MountedWeapons.Count; i++ )
            {
                Weapon w = (Weapon)Content.Weapons[MountedWeapons[i].Weapon];

                if (gt.TotalGameTime.TotalSeconds > MountedWeapons[i].WarmUpTime && 
                    w.RateOfFire > 0 && gt.TotalGameTime.TotalSeconds - LastShot[i] > w.RateOfFire)
                {
                    SM.AddEnemyProjectile(new Bullet(bounds.topLeft + MountedWeapons[i].Location, MountedWeapons[i].Aim, w.ProjectileDamage, w.ProjectileTexture));
                    LastShot[i] = gt.TotalGameTime.TotalSeconds;
                }
            }
        }
    }
}
